package com.wpw.dream.future;

public class FutureData implements Data {

	private RealData realData;
	
	private Boolean isDone = false;
	
	public synchronized void setRealData(RealData realData) {
		if (isDone) {
			return;
		}
		this.realData = realData;
		isDone = true;
		notifyAll();
	}
	
	
	@Override
	public synchronized Object getResult() {
		while (!isDone) {
			try {
				wait();
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
		return realData.getResult();
	}

}
